package com.wind.taobao.api.sns.convert
{
	import com.wind.taobao.api.sns.model.Album;
	import com.wind.taobao.core.util.TaobaoConstants;

	import mx.collections.ArrayCollection;


	/**
	 * Album转换器
	 * @author fxy
	 *
	 */
	public class AlbumConvert
	{
		/**
		 * 转换Album集合
		 */
		public static function convertAlbums(value:Object, type:String="json"):ArrayCollection
		{
			var albums:ArrayCollection=new ArrayCollection();
			if (value != null)
			{
				if (type == TaobaoConstants.JSON)
				{
					if ((value as Array).length > 0)
					{
						for (var i:uint=0; i < (value as Array).length; i++)
						{
							albums.addItem(convertAlbum((value as Array)[i]));
						}
					}
				}
				else
				{
					//TODO
				}
			}
			return albums;
		}

		/**
		 * 转换Album
		 */
		public static function convertAlbum(value:Object, type:String="json"):Album
		{
			var album:Album=new Album();
			if (value == null)
				return album;
			if (type == TaobaoConstants.XML)
			{
				album=convertXMLToAlbum(XML(value), album);
			}
			else
			{
				album=convertJSONToAlbum(value, album);
			}
			return album;
		}

		/**
		 * JSON转换为Album
		 */
		private static function convertJSONToAlbum(json:Object, album:Album):Album
		{
			if (json.hasOwnProperty(TaobaoConstants.ID))
			{
				album.id=json[TaobaoConstants.ID];
			}
			if (json.hasOwnProperty(TaobaoConstants.UID))
			{
				album.uid=json[TaobaoConstants.UID];
			}
			if (json.hasOwnProperty(TaobaoConstants.NAME))
			{
				album.name=json[TaobaoConstants.NAME];
			}
			if (json.hasOwnProperty(TaobaoConstants.NICK))
			{
				album.nick=json[TaobaoConstants.NICK];
			}
			if (json.hasOwnProperty(TaobaoConstants.MEMO))
			{
				album.memo=json[TaobaoConstants.MEMO];
			}
			if (json.hasOwnProperty(TaobaoConstants.COVER_URL))
			{
				album.cover_url=json[TaobaoConstants.COVER_URL];
			}
			if (json.hasOwnProperty(TaobaoConstants.PIC_COUNT))
			{
				album.pic_count=json[TaobaoConstants.PIC_COUNT];
			}
			return album;
		}

		/**
		 * XML转换为Album
		 */
		private static function convertXMLToAlbum(value:XML, album:Album):Album
		{
			return album;
		}

	}
}